# -*- coding: utf-8 -*-

'''
/**
 * @addtogroup az_module2
 * az_module2
 * @{
 */
/**
 * @file        az_module2.py
 * @brief       XXXX
 * @note        XXXX
 * @author      靳普诏(puzhao.jin@hopechart.com)
 * @date        2024/04/18
 * @version     1.0

 * @par         修改日志
 * <table>
 * <tr><th>Date         <th>Version     <th>Author      <th> Description
 * <tr><td>2024/04/18   <td>1.0         <td>靳普诏       <td> 创建初始版本
 * @copyright   xxxx
 */
'''

import sys
import os
import datetime

# 获取当前日期和时间
current_datetime = datetime.datetime.now()
# 格式化输出当前日期和时间
formatted_date = current_datetime.strftime("%Y-%m-%d")
formatted_time = current_datetime.strftime("%H:%M:%S")

# 输出格式化后的日期和时间
print(f"当前日期和时间: {formatted_date} {formatted_time}")

from pyazlib import EasyXlsx
from pyazlib.EasyJinja2 import TEasyJinja2


## 获取当前脚本所在的目录
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
# 输出目录路径
print("SCRIPT_DIR: "+ SCRIPT_DIR)


def ReadExcelParamList(xlsx_name:str, sheet_name:str) -> list :
    '''
    @brief       XXXX
    @param[in]   xlsx_name:str     XXXX
    @param[in]   sheet_name:str    XXXX
    @return      list     XXXX
    '''
    # 打开Excel文件
    xlsx_file = EasyXlsx.TXlsx(xlsx_name)
    
    # 获取所有单元格内容
    param_list = xlsx_file.sheetToDictListByRow(sheet_name)

    return param_list
    



def AzModule2_XlsxRowMode(xlsx_name:str, sheet_name:str, ja2_template:str, output_file:str) -> str:
    result = ""
    
    # 打开Excel文件
    xlsx_file = EasyXlsx.TXlsx(xlsx_name)

    # 读取Excel文件定义参数列表
    read_excel_param_list = xlsx_file.sheetToDictListByRow(sheet_name)

    ja2 = TEasyJinja2(f"{SCRIPT_DIR}/ref/j2_templates")

    user = {"var_name":"jpz", "var_date":"Today", "var_param_list":read_excel_param_list}

    ja2.Render(user, ja2_template, output_file)

    return result




if __name__ == "__main__":
    ## 获取脚本传参
    argv = sys.argv
    argc = len(argv)
    # 打印命令行参数
    #for i in range(1, argc):
        #print("参数", i, ":", argv[i])
        
    print("============= BIGEN: az_module2.py =============")

    xlsx_name = f"{SCRIPT_DIR}/at_server_ext.xlsx"
    sheet_name = "set"
    ja2_template_dir = f"{SCRIPT_DIR}/ref/j2_templates"
    ja2_template_file_h = "hq_head.h.tpl"
    ja2_template_file_c ="at_server_ext.c.j2"
    output_file_h = f"{SCRIPT_DIR}/rte_bsc_netlink_atserver_attr.h"
    output_file_c = f"{SCRIPT_DIR}/at_server_ext.c"


    # 读取Excel文件定义参数列表
    read_excel_param_list = ReadExcelParamList(xlsx_name, sheet_name)

    ja2 = TEasyJinja2(ja2_template_dir)


    output_file_name = "at_server_ext"
    ja2_template_file_c = f"{output_file_name}.c.j2"
    output_file_c = f"{SCRIPT_DIR}/{output_file_name}.c"
    ja2_template_file_h = f"{output_file_name}.h.j2"
    output_file_h = f"{SCRIPT_DIR}/{output_file_name}.h"

    user = {"var_name":"python",
            "var_filename":"at_server_ext",
            "var_email":"xxx@hopechart.com",
            "var_date":formatted_date,
            "var_time":formatted_time,
            "var_param_list":read_excel_param_list}

    ja2.Render(user, ja2_template_file_c, output_file_c)
    ja2.Render(user, ja2_template_file_h, output_file_h)



    # output_file_name = "at_server_ext"
    # section_tag = "sys"
    # ja2_template_file_c = f"{output_file_name}-section.c.j2"
    # output_file_c = f"{SCRIPT_DIR}/{output_file_name}_{section_tag}.c"
    # ja2_template_file_h = f"{output_file_name}-section.h.j2"
    # output_file_h = f"{SCRIPT_DIR}/{output_file_name}_{section_tag}.h"

    # user = {"var_name":"python",
    #         "var_filename":f"{output_file_name}_{section_tag}",
    #         "var_email":"xxx@hopechart.com",
    #         "var_date":formatted_date,
    #         "var_time":formatted_time,
    #         "var_param_list":read_excel_param_list,
    #         "var_section_tag":f"{section_tag}."}

    # ja2.Render(user, ja2_template_file_c, output_file_c)
    # ja2.Render(user, ja2_template_file_h, output_file_h)


    section_tag_list = ['sys', 'fs', 'chip', 'SIM', 'ns', 'COPS', 'cfg', 'icfg', 'cid', 'ssl', 'ftp']

    for section_tag in section_tag_list:
        ja2_template_file_c = f"{output_file_name}-section.c.j2"
        output_file_c = f"{SCRIPT_DIR}/{output_file_name}_{section_tag}.c"
        ja2_template_file_h = f"{output_file_name}-section.h.j2"
        output_file_h = f"{SCRIPT_DIR}/{output_file_name}_{section_tag}.h"

        user = {"var_name":"python",
                "var_filename":f"{output_file_name}_{section_tag}".lower(),
                "var_email":"xxx@hopechart.com",
                "var_date":formatted_date,
                "var_time":formatted_time,
                "var_param_list":read_excel_param_list,
                "var_section_tag":f"_{section_tag}_"}

        ja2.Render(user, ja2_template_file_c, output_file_c.lower())
        ja2.Render(user, ja2_template_file_h, output_file_h.lower())


    section_tag = "icfg"
    ja2_template_file_c = f"{output_file_name}-section_{section_tag}.c.j2"
    output_file_c = f"{SCRIPT_DIR}/{output_file_name}_{section_tag}.c"

    user = {"var_name":"python",
            "var_filename":f"{output_file_name}_{section_tag}".lower(),
            "var_email":"xxx@hopechart.com",
            "var_date":formatted_date,
            "var_time":formatted_time,
            "var_param_list":read_excel_param_list,
            "var_section_tag":f"_{section_tag}_"}
    ja2.Render(user, ja2_template_file_c, output_file_c.lower())
    
    
    section_tag = "ssl"
    ja2_template_file_c = f"{output_file_name}-section_{section_tag}.c.j2"
    output_file_c = f"{SCRIPT_DIR}/{output_file_name}_{section_tag}.c"

    user = {"var_name":"python",
            "var_filename":f"{output_file_name}_{section_tag}".lower(),
            "var_email":"xxx@hopechart.com",
            "var_date":formatted_date,
            "var_time":formatted_time,
            "var_param_list":read_excel_param_list,
            "var_section_tag":f"_{section_tag}_"}
    ja2.Render(user, ja2_template_file_c, output_file_c.lower())
    
    
    section_tag = "ftp"
    ja2_template_file_c = f"{output_file_name}-section_{section_tag}.c.j2"
    output_file_c = f"{SCRIPT_DIR}/{output_file_name}_{section_tag}.c"

    user = {"var_name":"python",
            "var_filename":f"{output_file_name}_{section_tag}".lower(),
            "var_email":"xxx@hopechart.com",
            "var_date":formatted_date,
            "var_time":formatted_time,
            "var_param_list":read_excel_param_list,
            "var_section_tag":f"_{section_tag}_"}
    ja2.Render(user, ja2_template_file_c, output_file_c.lower())
    print("============= END: az_module2.py =============")



## Generated on "2024-04-18 17:19:58" by the tool "gen_hq_file.py >> V20231119" 

